package com.ysq.www.common.result;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

@Data
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)//返回结果中有null值，干掉它！
public class ResultMsg<T> {

    private T data;

    private Integer code;

    private String msg;

    public ResultMsg() {
    }

    public ResultMsg(Integer code, String msg,T data) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public ResultMsg(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 配合静态对象直接设置 data 参数
     * @param data
     * @return
     */
    public ResultMsg setNewData(T data){
        ResultMsg msg = new ResultMsg();
        msg.setCode(this.code);
        msg.setMsg(this.msg);
        msg.setData(data);
        return msg;
    }

    /**
     * 配合静态对象直接设置 msg 参数
     * @param msg
     * @return
     */
    public ResultMsg setNewMsg(String msg){
        ResultMsg rMsg = new ResultMsg();
        rMsg.setCode(this.code);
        rMsg.setData(this.data);
        rMsg.setMsg(msg);
        return rMsg;
    }

    public ResultMsg(ResultStatusCode resultStatusCode,T data){
        this(resultStatusCode.getCode(),resultStatusCode.getMsg(),data);
    }

    public ResultMsg(ResultStatusCode resultStatusCode){
        this(resultStatusCode,null);
    }

    public static final ResultMsg SUCCESS = new ResultMsg(200,"成功");

    public static final ResultMsg INSERT_SUCCESS = new ResultMsg(200,"新增成功");

    public static final ResultMsg UPDATE_SUCCESS = new ResultMsg(200,"更新成功");

    public static final ResultMsg DELETE_SUCCESS = new ResultMsg(200,"删除成功");

    public static final ResultMsg UPLOAD_SUCCESS = new ResultMsg(200,"上传成功");

    public static final ResultMsg DOWNLOAD_SUCCESS = new ResultMsg(200,"下载成功");

    public static final ResultMsg LOGIN_SUCCESS = new ResultMsg(200,"登录成功");

    public static final ResultMsg LOGOUT_SUCCESS = new ResultMsg(200,"登出成功");

    public static final ResultMsg WX_AUTHOR_SUCCESS = new ResultMsg(200, "微信授权成功");

    public static final ResultMsg LOGIN_ERROR = new ResultMsg(201,"登录错误");

    public static final ResultMsg LOGIN_EXPIRE = new ResultMsg(202,"登录过期");

    public static final ResultMsg ACCESS_LIMITED = new ResultMsg(301, "访问受限");

    public static final ResultMsg WX_AUTHOR_ERROR = new ResultMsg(406, "微信授权失败");

    public static final ResultMsg ARGS_ERROR = new ResultMsg(501, "参数错误");

    public static final ResultMsg UNKNOWN_ERROR = new ResultMsg(502, "系统异常");

    public static final ResultMsg INSERT_ERROR = new ResultMsg(503, "新增错误");

    public static final ResultMsg UPDATE_ERROR = new ResultMsg(504, "更新错误");

    public static final ResultMsg DELETE_ERROR = new ResultMsg(506, "删除错误");

    public static final ResultMsg UPLOAD_ERROR = new ResultMsg(507, "上传错误");

    public static final ResultMsg DOWNLOAD_ERROR = new ResultMsg(508, "下载错误");

    public static final ResultMsg OTHER_SYSTEM_ERROR = new ResultMsg(509, "调用系统异常");

}
